﻿<Window x:Class="Ellanet.Windows.PractiseWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:converters="clr-namespace:Ellanet.Converters"
        mc:Ignorable="d"
        Title="Test" Height="550" Width="1000" WindowStartupLocation="CenterScreen" WindowStyle="None" ResizeMode="NoResize" Topmost="False" ShowInTaskbar="True" Background="Transparent" AllowsTransparency="True" Icon="/Resources/Minion-Reading-icon.png">
    <Window.Resources>
        <converters:IntToImageSourceListConverter x:Key="IntToImageSourceListConverter"/>
        <converters:NullToBoolConverter x:Key="NullToBoolConverter"/>
        <converters:ChoiceIsCorrectToImageConverter x:Key="ChoiceIsCorrectToImageConverter"/>
        <converters:MillisecondsToSecondsStringConverter x:Key="MillisecondsToSecondsStringConverter"/>
        <Style TargetType="Image" x:Key="StandardImageStyle">
            <Setter Property="Stretch" Value="Uniform"/>
            <Setter Property="Height" Value="300"/>
            <Setter Property="RenderOptions.BitmapScalingMode" Value="HighQuality"/>
            <Style.Triggers>
                <DataTrigger Binding="{Binding NotifyOnTargetUpdated=True, Converter={StaticResource NullToBoolConverter}}" Value="False">
                    <DataTrigger.EnterActions>
                        <BeginStoryboard>
                            <Storyboard>
                                <DoubleAnimation Storyboard.TargetProperty="Opacity" From="0.0" To="1.0" Duration="0:0:1.5"/>
                            </Storyboard>
                        </BeginStoryboard>
                    </DataTrigger.EnterActions>
                </DataTrigger>
            </Style.Triggers>
        </Style>
    </Window.Resources>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="360"/>
            <RowDefinition Height="30"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
        <Rectangle Grid.Row="0" Style="{StaticResource BackgroundRectangleStyle}"/>
        <Grid Grid.Row="0">
            <Grid.ColumnDefinitions>
                <ColumnDefinition/>
                <ColumnDefinition Width="300"/>
                <ColumnDefinition/>
            </Grid.ColumnDefinitions>
            <ItemsControl Grid.Column ="0" ItemsSource="{Binding Path=Sum.Multiplicand, NotifyOnTargetUpdated=True, Converter={StaticResource IntToImageSourceListConverter}}">
                <ItemsControl.ItemsPanel>
                    <ItemsPanelTemplate>
                        <StackPanel Orientation="Horizontal" HorizontalAlignment="Right"/>
                    </ItemsPanelTemplate>
                </ItemsControl.ItemsPanel>
                <ItemsControl.ItemTemplate>
                    <DataTemplate>
                        <Image Source="{Binding}" Style="{StaticResource StandardImageStyle}"/>
                    </DataTemplate>
                </ItemsControl.ItemTemplate>
            </ItemsControl>
            <Image Grid.Column="1" Source="/Resources/X_Purple.png" Style="{StaticResource StandardImageStyle}" Width="200"/>
            <ItemsControl Grid.Column ="2" ItemsSource="{Binding Path=Sum.Multiplier, NotifyOnTargetUpdated=True, Converter={StaticResource IntToImageSourceListConverter}}">
                <ItemsControl.ItemsPanel>
                    <ItemsPanelTemplate>
                        <StackPanel Orientation="Horizontal" HorizontalAlignment="Left"/>
                    </ItemsPanelTemplate>
                </ItemsControl.ItemsPanel>
                <ItemsControl.ItemTemplate>
                    <DataTemplate>
                        <Image Source="{Binding}" Style="{StaticResource StandardImageStyle}"/>
                    </DataTemplate>
                </ItemsControl.ItemTemplate>
            </ItemsControl>
        </Grid>
        <Border Grid.Row="0" Style="{StaticResource WindowBorderStyle}"/>
        <Grid Grid.Row="2" Width="720">
            <Rectangle Style="{StaticResource BackgroundRectangleStyle}"/>
            <Border Style="{StaticResource WindowBorderStyle}"/>
            <ItemsControl Grid.Column ="0" ItemsSource="{Binding Path=Choices, NotifyOnTargetUpdated=True}">
                <ItemsControl.ItemsPanel>
                    <ItemsPanelTemplate>
                        <StackPanel Orientation="Horizontal" HorizontalAlignment="Center"/>
                    </ItemsPanelTemplate>
                </ItemsControl.ItemsPanel>
                <ItemsControl.ItemTemplate>
                    <DataTemplate>
                        <Button Width="125" Height="75" Margin="20,0,20,0" Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=DataContext.AnswerCommand}" CommandParameter="{Binding}">
                            <Button.Style>
                                <Style TargetType="Button" BasedOn="{StaticResource {x:Type Button}}">
                                    <Setter Property="Content">
                                        <Setter.Value>
                                            <ItemsControl Grid.Column ="0" ItemsSource="{Binding Path=Answer, NotifyOnTargetUpdated=True, Converter={StaticResource IntToImageSourceListConverter}}">
                                                <ItemsControl.ItemsPanel>
                                                    <ItemsPanelTemplate>
                                                        <StackPanel Orientation="Horizontal" HorizontalAlignment="Right"/>
                                                    </ItemsPanelTemplate>
                                                </ItemsControl.ItemsPanel>
                                                <ItemsControl.ItemTemplate>
                                                    <DataTemplate>
                                                        <Image Source="{Binding}" Style="{StaticResource StandardImageStyle}" Height="50"/>
                                                    </DataTemplate>
                                                </ItemsControl.ItemTemplate>
                                            </ItemsControl>
                                        </Setter.Value>
                                    </Setter>
                                    <Style.Triggers>
                                        <DataTrigger Binding="{Binding Path=IsChosen, NotifyOnTargetUpdated=True}" Value="True">
                                            <Setter Property="Content">
                                                <Setter.Value>
                                                    <Image Source="{Binding Path=IsCorrect, Converter={StaticResource ChoiceIsCorrectToImageConverter}}" Style="{StaticResource StandardImageStyle}" Height="65"/>
                                                </Setter.Value>
                                            </Setter>
                                        </DataTrigger>
                                    </Style.Triggers>
                                </Style>
                            </Button.Style>
                        </Button>
                    </DataTemplate>
                </ItemsControl.ItemTemplate>
            </ItemsControl>
        </Grid>
        <Grid Grid.Row="1" Width="130" Margin="-30">
            <Rectangle Style="{StaticResource BackgroundRectangleStyle}"/>
            <TextBlock Text="{Binding Path=SumTime.TotalMilliseconds, NotifyOnTargetUpdated=True, Converter={StaticResource MillisecondsToSecondsStringConverter}}" HorizontalAlignment="Center" VerticalAlignment="Center" Foreground="{StaticResource StandardDarkControlSolidColorBrush}" FontSize="36">
                <TextBlock.Style>
                    <Style TargetType="TextBlock">
                        <Setter Property="Visibility" Value="Hidden"/>
                        <Style.Triggers>
                            <DataTrigger Binding="{Binding Path=IsSumAwaitingAnswer, NotifyOnTargetUpdated=True}" Value="True">
                                <Setter Property="Visibility" Value="Visible"/>
                            </DataTrigger>
                        </Style.Triggers>
                    </Style>
                </TextBlock.Style>
            </TextBlock>
            <Border Style="{StaticResource WindowBorderStyle}"/>
        </Grid>
        <Button Grid.Row="2" Grid.Column="0" IsCancel="True" Opacity="0.0" Width="1" Height="1" HorizontalAlignment="Right" VerticalAlignment="Bottom" Click="CloseButton_OnClick"/>
    </Grid>
</Window>
